/*     */ package com.wgcloud.util;
/*     */ 
/*     */ import cn.hutool.json.JSONObject;
/*     */ import cn.hutool.json.JSONUtil;
/*     */ import com.wgcloud.util.DateUtil;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import org.apache.commons.lang3.StringUtils;
/*     */ import org.slf4j.Logger;
/*     */ import org.slf4j.LoggerFactory;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.http.HttpEntity;
/*     */ import org.springframework.http.HttpHeaders;
/*     */ import org.springframework.http.HttpMethod;
/*     */ import org.springframework.http.MediaType;
/*     */ import org.springframework.http.ResponseEntity;
/*     */ import org.springframework.stereotype.Component;
/*     */ import org.springframework.util.MultiValueMap;
/*     */ import org.springframework.web.client.HttpClientErrorException;
/*     */ import org.springframework.web.client.RestTemplate;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ @Component
/*     */ public class RestUtil
/*     */ {
/*  28 */   private Logger logger = LoggerFactory.getLogger(com.wgcloud.util.RestUtil.class);
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   @Autowired
/*     */   private RestTemplate restTemplate;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   
/*     */   public Map<String, Integer> post(String url, String postStr, String keyWord) {
/*  42 */     Map<String, Integer> responseMap = new HashMap<>();
/*     */     try {
/*  44 */       responseMap.put("resTimes", Integer.valueOf(20000));
/*  45 */       long startTimes = DateUtil.getNowTime().getTime();
/*  46 */       HttpHeaders headers = new HttpHeaders();
/*  47 */       headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
/*  48 */       headers.add("Accept", MediaType.APPLICATION_JSON_UTF8.toString());
/*  49 */       headers.set("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:50.0) Gecko/20100101 Firefox/50.0");
/*  50 */       HttpEntity<String> httpEntity = new HttpEntity(postStr, (MultiValueMap)headers);
/*  51 */       ResponseEntity<String> responseEntity = this.restTemplate.postForEntity(url, httpEntity, String.class, new Object[0]);
/*  52 */       long endTimes = DateUtil.getNowTime().getTime();
/*  53 */       String resTimes = (endTimes - startTimes) + "";
/*  54 */       responseMap.put("resTimes", Integer.valueOf(resTimes));
/*  55 */       responseMap.put("heathStatus", Integer.valueOf(responseEntity.getStatusCodeValue()));
/*  56 */       this.logger.debug((String)responseEntity.getBody());
/*  57 */       if (!StringUtils.isEmpty(keyWord) && 
/*  58 */         !((String)responseEntity.getBody()).contains(keyWord)) {
/*  59 */         this.logger.error(url + "----响应内容没有含标识-------" + keyWord);
/*  60 */         responseMap.put("heathStatus", Integer.valueOf(500));
/*     */       } 
/*     */       
/*  63 */       return responseMap;
/*  64 */     } catch (HttpClientErrorException e) {
/*  65 */       this.logger.error("服务接口检测任务错误", (Throwable)e);
/*  66 */       responseMap.put("heathStatus", Integer.valueOf(e.getRawStatusCode()));
/*  67 */       return responseMap;
/*  68 */     } catch (Exception e) {
/*  69 */       this.logger.error("服务接口检测任务错误", e);
/*  70 */       responseMap.put("heathStatus", Integer.valueOf(500));
/*  71 */       return responseMap;
/*     */     } 
/*     */   }
/*     */   
/*     */   public JSONObject post(String url, JSONObject jsonObject) {
/*  76 */     HttpHeaders headers = new HttpHeaders();
/*  77 */     headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
/*  78 */     headers.add("Accept", MediaType.APPLICATION_JSON_UTF8.toString());
/*  79 */     HttpEntity<String> httpEntity = new HttpEntity(JSONUtil.parse(jsonObject).toString(), (MultiValueMap)headers);
/*  80 */     ResponseEntity<String> responseEntity = this.restTemplate.postForEntity(url, httpEntity, String.class, new Object[0]);
/*  81 */     return JSONUtil.parseObj((String)responseEntity.getBody());
/*     */   }
/*     */   
/*     */   public JSONObject post(String url) {
/*  85 */     HttpHeaders headers = new HttpHeaders();
/*  86 */     headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
/*  87 */     headers.add("Accept", MediaType.APPLICATION_JSON_UTF8.toString());
/*  88 */     HttpEntity<String> httpEntity = new HttpEntity("", (MultiValueMap)headers);
/*  89 */     ResponseEntity<String> responseEntity = this.restTemplate.postForEntity(url, httpEntity, String.class, new Object[0]);
/*  90 */     return JSONUtil.parseObj((String)responseEntity.getBody());
/*     */   }
/*     */   
/*     */   public Map<String, Integer> get(String url, String keyWord) {
/*  94 */     Map<String, Integer> responseMap = new HashMap<>();
/*     */     try {
/*  96 */       responseMap.put("resTimes", Integer.valueOf(20000));
/*  97 */       long startTimes = DateUtil.getNowTime().getTime();
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */       
/* 104 */       ResponseEntity<String> responseEntity = null;
/* 105 */       if (url.startsWith("https")) {
/* 106 */         HttpHeaders headers = new HttpHeaders();
/* 107 */         headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
/* 108 */         headers.add("Accept", MediaType.APPLICATION_JSON_UTF8.toString());
/* 109 */         headers.set("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:50.0) Gecko/20100101 Firefox/50.0");
/* 110 */         HttpEntity<String> httpEntity = new HttpEntity("", (MultiValueMap)headers);
/* 111 */         responseEntity = this.restTemplate.exchange(url, HttpMethod.GET, httpEntity, String.class, new Object[0]);
/*     */       } else {
/* 113 */         responseEntity = this.restTemplate.getForEntity(url, String.class, new Object[0]);
/*     */       } 
/* 115 */       long endTimes = DateUtil.getNowTime().getTime();
/* 116 */       String resTimes = (endTimes - startTimes) + "";
/* 117 */       responseMap.put("resTimes", Integer.valueOf(resTimes));
/* 118 */       responseMap.put("heathStatus", Integer.valueOf(responseEntity.getStatusCodeValue()));
/* 119 */       this.logger.debug((String)responseEntity.getBody());
/* 120 */       if (!StringUtils.isEmpty(keyWord) && 
/* 121 */         !((String)responseEntity.getBody()).contains(keyWord)) {
/* 122 */         this.logger.error(url + "----响应内容没有含标识-------" + keyWord);
/* 123 */         responseMap.put("heathStatus", Integer.valueOf(500));
/*     */       } 
/*     */       
/* 126 */       return responseMap;
/* 127 */     } catch (HttpClientErrorException e) {
/* 128 */       this.logger.error("服务接口检测任务错误", (Throwable)e);
/* 129 */       responseMap.put("heathStatus", Integer.valueOf(e.getRawStatusCode()));
/* 130 */       return responseMap;
/* 131 */     } catch (Exception e) {
/* 132 */       this.logger.error("服务接口检测任务错误", e);
/* 133 */       responseMap.put("heathStatus", Integer.valueOf(500));
/* 134 */       return responseMap;
/*     */     } 
/*     */   }
/*     */ 
/*     */   
/*     */   public String get(String url) {
/*     */     try {
/* 141 */       ResponseEntity<String> responseEntity = null;
/* 142 */       if (url.startsWith("https")) {
/* 143 */         HttpHeaders headers = new HttpHeaders();
/* 144 */         headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
/* 145 */         headers.add("Accept", MediaType.APPLICATION_JSON_UTF8.toString());
/* 146 */         headers.set("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:50.0) Gecko/20100101 Firefox/50.0");
/* 147 */         HttpEntity<String> httpEntity = new HttpEntity("", (MultiValueMap)headers);
/* 148 */         responseEntity = this.restTemplate.exchange(url, HttpMethod.GET, httpEntity, String.class, new Object[0]);
/*     */       } else {
/* 150 */         responseEntity = this.restTemplate.getForEntity(url, String.class, new Object[0]);
/*     */       } 
/* 152 */       return (String)responseEntity.getBody();
/* 153 */     } catch (HttpClientErrorException e) {
/* 154 */       this.logger.error("请求守护进程信息错误", (Throwable)e);
/* 155 */       return "";
/* 156 */     } catch (Exception e) {
/* 157 */       this.logger.error("请求守护进程信息错误", e);
/* 158 */       return "";
/*     */     } 
/*     */   }
/*     */ }


/* Location:              /Users/zhangyongxin/soft-install/wgcloud/wgcloud-v3.3.5/server/bank/wgcloud-server-release.jar!/BOOT-INF/classes/com/wgcloud/util/RestUtil.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */